#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
'''
Created on 11/01/2014

@author: Jesus Gomez
'''
import urllib2
import re

types = [12,15,14,9,2,6,5,13]
pages = [43,78,61,95,108,90,64,153]
pos_list = []

f = open('ids.txt','w')

n=0

for type in types:
    for i in range(1,pages[n]+1):
        pos_list.append('tipo='+str(type)+"&pag="+str(i))
    n = n + 1



for url_pos in pos_list:
    url_prefix = 'http://www.recetas.net/recetario/recetario_listado.asp?' 
    
    url = url_prefix + url_pos

    usock = urllib2.urlopen(url);
    data = usock.read()
    
    usock.close()
    
    for m in re.finditer( '\.asp\?ID=', data ):
        print( 'found! ',"the id is",data[m.end():m.end()+6] )
        f.write(data[m.end():m.end()+6]+'\n')
        
f.close()